﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using jiaju.Models;
using jiaju.Models.DBModel;

namespace jiaju.Models.DAL
{
    public class MessageService
    {
        //留言
        public static Message getMessage()
        {
            string sql = "select Name,Tel,Email,Cont from dbo.Message";
            Message message = null;          
            SqlDataReader sdr = DBHelp.ExecuteReader(sql);
            while (sdr.Read())
            {
                string Name = (string)sdr["Name"];
                string Tel = (string)sdr["Tel"];
                string Email = (string)sdr["Email"];
                string Cont = (string)sdr["Cont"];
                message = new Message()
                {
                    Name = Name,
                    Tel = Tel,
                    Email = Email,
                    Cont = Cont
                };              
            }
            return message;
        }
        //提交
        public static int SubMessage(Message art)
        {
            String sql = string.Format(@"insert into dbo.Message
            (Name,
             Tel,
             Email,
             Cont           
             )
         values('{0}','{1}','{2}','{3}')",art.Name, art.Tel, art.Email, art.Cont);
            int num = DBHelp.ExecuteNonQuery(sql);
            return num;
        }
    }
}